#include "questionnaire.h"
#include "ui_questionnaire.h"
#include <QHostInfo>
#include <QMessageBox>

questionnaire::questionnaire(QWidget* parent)
    : QWidget(parent)
    , ui(new Ui::questionnaire)
{
    ui->setupUi(this);
    m_tcpsocket = new QTcpSocket(this);
    int port = 8010;
    QString ip = "127.0.0.1";
    m_tcpsocket->connectToHost(ip, port);
    connect(m_tcpsocket, &QTcpSocket::connected, this, &questionnaire::connected_Slot);

}

questionnaire::~questionnaire()
{
    delete ui;
}


void questionnaire::on_pushButton_clicked()
{
    m_tcpsocket->write(ui->labelName->text().toUtf8());
    m_tcpsocket->write(ui->lineEditName->text().toUtf8());
    m_tcpsocket->write("   ");
    m_tcpsocket->write(ui->labelAge->text().toUtf8());
    m_tcpsocket->write(ui->lineEditAge->text().toUtf8());
    m_tcpsocket->write("   ");
    m_tcpsocket->write(ui->labelClass->text().toUtf8());
    m_tcpsocket->write(ui->lineEditClass->text().toUtf8());
    m_tcpsocket->write("   ");
    m_tcpsocket->write(ui->labelHobby->text().toUtf8());
    m_tcpsocket->write(ui->lineEditHobby->text().toUtf8());
    ui->lineEditName->clear();
    ui->lineEditAge->clear();
    ui->lineEditClass->clear();
    ui->lineEditHobby->clear();
    QMessageBox::warning(this, "提交成功", "服务器已收到问卷");
}
void questionnaire::connected_Slot()
{

    //    m_tcpsocket = m_tcpserver->nextPendingConnection();
    connect(m_tcpsocket, &QTcpSocket::readyRead, this, &questionnaire::readyRead);
}
void questionnaire::readyRead()
{

}

